<head>
	<link rel="stylesheet" type="text/css" href="style/default.css" />
</head>


<?php
session_start();

include("view/UserView.php");

$action = null;
if (isset($_REQUEST["action"])) {
	$action = $_REQUEST["action"];
}

if ($action == "login") {
	include("action/LoginAction.php");
	exit;
}

if ($action == "logout") {
	include("action/LogoutAction.php");
	exit;
}

/*
 * Check if the user is valid.  Otherwise, include the login page and return.
 */
$userValid = false;
if (isset($_SESSION["userValid"])) {
	$userValid = true;
} 

if (!$userValid) {
	include("view/LoginForm.inc");
	exit;
}

if (!isset($action) || $action == "null") {

    print <<<HTML
<a href="?action=logout">Logout</a><br/><br/>
<a href="?action=viewPayStations">Pay Stations</a>&nbsp;|&nbsp;<a href="?action=viewDepartments">Departments</a>&nbsp;|&nbsp;<a href="?action=viewUnlock">Unlock document</a>&nbsp;|&nbsp;<a href="?action=viewCaseType">Case Type</a>
HTML;
	/*
	 * Display the home page.
	 */
print <<<HTML
	

	<h1>Users</h1>
	<a href="?action=editUser">Add User</a>
HTML;
	include("view/UserTable.inc");
	
} else {
	/*
	 * If an action is specified, display the appropriate information.
	 */
	if ($action == "editUser") {
		include("view/UserForm.inc");
	}
	
	/*
	 * Adds a user.
	 */
	if ($action == "setUser") {
		include("action/SetUser.php");	
	}
	
	/*
	 * Deletes a user.
	 */	
	if ($action == "deleteUser") {
		include("action/DeleteUser.php");
	}
	
	/*
	 * New Pay Station (view)
	 */
	if ($action == "newPayStation") {
		include("view/NewPayStationForm.inc");
	}
	
	/*
	 * Edits a Pay Station
	 */
	 if ($action == "editPayStation") {
	 	include("view/PayStationForm.inc");
	 }
	 
	 /*
	  * Updates a Pay Station
	  */
	 if ($action == "setPayStation") {
		include("action/UpdatePayStation.php");	 	
	 }
	 
	 /*
	  * Adds a Pay Station
	  */
	 if ($action == "addPayStation") {
		include("action/AddPayStation.php");	 	
	 }
	 
	 /*
	  * View Pay Stations
	  */
	 if ($action == 'viewPayStations') {
	        print <<<HTML
			<a href="?action=logout">Logout</a><br/><br/>
			<a href="./">Users</a>&nbsp;|&nbsp;<a href="?action=viewDepartments">Departments</a>&nbsp;|&nbsp;<a href="?action=viewUnlock">Unlock document</a>&nbsp;|&nbsp;<a href="?action=viewCaseType">Case Type</a>
HTML;
			include("view/PayStationTable.inc");
	 }

	/*
	 * View Departments
	 */
	if ($action == "viewDepartments") {
		print <<<HTML
			<a href="?action=logout">Logout</a><br/><br/>
			<a href="./">Users</a>&nbsp;|&nbsp;<a href="?action=viewPayStations">Pay Stations</a>&nbsp;|&nbsp;<a href="?action=viewUnlock">Unlock document</a>&nbsp;|&nbsp;<a href="?action=viewCaseType">Case Type</a>
HTML;
		include("view/DepartmentTable.inc");
	}
	
	/*
	 * Edit a department
	 */
	if ($action == "editDepartment") {
		include("view/DepartmentForm.inc");
	}
	
	/*
	 * Adds a department.
	 */
	if ($action == "setDepartment") {
		include("action/SetDepartment.php");	
	}
	
	/*
	 * Deletes a department.
	 */	
	if ($action == "deleteDepartment") {
		include("action/DeleteDepartment.php");
	}
	
	/*
	 * View Unlock documents
	 */
	if ($action == "viewUnlock") {
		print <<<HTML
			<a href="?action=logout">Logout</a><br/><br/>
			<a href="./">Users</a>&nbsp;|&nbsp;<a href="?action=viewPayStations">Pay Stations</a>&nbsp;|&nbsp;<a href="?action=viewDepartments">Departments</a>&nbsp;|&nbsp;<a href="?action=viewCaseType">Case Type</a>
HTML;
		include("view/UnlockForm.inc");
	}
	
	/*
	 * Unlock document
	 */
	if ($action == "unlockDoc") {
		include("action/UnlockDoc.php");
	}
	
	/*
	 * Unlock document bulk
	 */
	if ($action == "unlockDocBulk") {
		include("action/UnlockDocBulk.php");
	}
	
	/*
	 * Unlock document by date range
	 */
	if ($action == "unlockDateRange") {
		include("action/UnlockDateRange.php");	
	}
	
	/*
	 * View Case Types
	 */
	if ($action == "viewCaseType") {
		print <<<HTML
			<a href="?action=logout">Logout</a><br/><br/>
			<a href="./">Users</a>&nbsp;|&nbsp;<a href="?action=viewPayStations">Pay Stations</a>&nbsp;|&nbsp;<a href="?action=viewDepartments">Departments</a>&nbsp;|&nbsp;<a href="?action=viewUnlock">Unlock document</a>
HTML;
		include("view/CaseTypeTable.inc");
	}
	
	/*
	 * View Edit Case Type
	 */
	if ($action == "editCaseType") {
		include("view/CaseTypeForm.inc");
	}
	
	/*
	 * Delete Case Type
	 */
	if ($action == "deleteCaseType") {
		include("action/DeleteCaseType.php");
	}
	
	/*
	 * Set Case Type
	 */
	if ($action == "setCaseType") {
		include("action/SetCaseType.php");	
	}

}

?>